package com.liu.queue.message;

import com.liu.message.impl.ResponseMessage;
import com.liu.queue.message.impl.PullOrdinaryRequestMessage;
import com.liu.queue.message.impl.PushOrdinaryReqeustMessage;

public enum MessageTypeEnum {
    // 方便进行扩展,例如顺序消息使用byte类型12
    PUSH_ORDINARY_REQUEST((byte) 1, PushOrdinaryReqeustMessage.class),
    PULL_ORDINARY_REQUEST((byte) 2, PullOrdinaryRequestMessage.class),
    RESPONSE((byte) 3, ResponseMessage.class);

    private byte type;
    private Class<?> clazz;


    public byte getType() {
        return type;
    }

    public Class<?> getClazz() {
        return clazz;
    }

    MessageTypeEnum(byte type, Class<?> clazz) {
        this.type = type;
        this.clazz = clazz;
    }


    public static MessageTypeEnum get(byte type) {
        for (MessageTypeEnum value : values()) {
            if (value.type == type) {
                return value;
            }
        }
        throw new RuntimeException("未知类型: " + type);
    }

    public static MessageTypeEnum get(MessageTypeEnum messageType) {
        for (MessageTypeEnum value : values()) {
            if (value == messageType) {
                return value;
            }
        }
        throw new RuntimeException("未知类型: " + messageType);
    }
}